package com.ruoyi.module.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.page.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.module.app.domain.WarehouseLogisticsPrice;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.module.app.service.IWarehouseLogisticsPriceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.Result;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 仓库物流单价配置Controller
 *
 * @author mars
 * @date 2022-11-30
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/app/logisticsPrice" )
public class WarehouseLogisticsPriceController extends BaseController {

    private final IWarehouseLogisticsPriceService iWarehouseLogisticsPriceService;

    /**
     * 查询仓库物流单价配置列表
     */
    @PreAuthorize("@ss.hasPermi('app:logisticsPrice:list')")
    @GetMapping("/list")
    public PageInfo list(WarehouseLogisticsPrice warehouseLogisticsPrice) {
        return iWarehouseLogisticsPriceService.findPageBySpec(warehouseLogisticsPrice);
    }

    /**
     * 获取仓库物流单价配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:logisticsPrice:query')" )
    @GetMapping(value = "/query/{id}" )
    public Result getInfo(@PathVariable("id" ) Long id) {
        return Result.success(iWarehouseLogisticsPriceService.getById(id));
    }

    /**
     * 新增仓库物流单价配置
     */
    @PreAuthorize("@ss.hasPermi('app:logisticsPrice:add')" )
    @Log(title = "仓库物流单价配置" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody WarehouseLogisticsPrice warehouseLogisticsPrice) {
        return Result.success("新增成功",iWarehouseLogisticsPriceService.add(warehouseLogisticsPrice));
    }

    /**
     * 修改仓库物流单价配置
     */
    @PreAuthorize("@ss.hasPermi('app:logisticsPrice:edit')" )
    @Log(title = "仓库物流单价配置" , businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result edit(@RequestBody WarehouseLogisticsPrice warehouseLogisticsPrice) {
        return toAjax(iWarehouseLogisticsPriceService.update(warehouseLogisticsPrice) ? 1 : 0);
    }

    /**
     * 删除仓库物流单价配置
     */
    @PreAuthorize("@ss.hasPermi('app:logisticsPrice:remove')" )
    @Log(title = "仓库物流单价配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}" )
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(iWarehouseLogisticsPriceService.deleteBatch(Arrays.asList(ids)) ? 1 : 0);
    }

    /**
     * 导出仓库物流单价配置列表
     */
    @PreAuthorize("@ss.hasPermi('app:logisticsPrice:export')" )
    @Log(title = "仓库物流单价配置" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public Result export(WarehouseLogisticsPrice warehouseLogisticsPrice) {
        LambdaQueryWrapper<WarehouseLogisticsPrice> lqw = new LambdaQueryWrapper<WarehouseLogisticsPrice>(warehouseLogisticsPrice);
        List<WarehouseLogisticsPrice> list = iWarehouseLogisticsPriceService.list(lqw);
        ExcelUtil<WarehouseLogisticsPrice> util = new ExcelUtil<WarehouseLogisticsPrice>(WarehouseLogisticsPrice. class);
        return util.exportExcel(list, "logisticsPrice" );
    }
}
